WIP solving #174#175
Conversation
Codecov Report
@@ Coverage Diff @@
## master #175 +/- ##
==========================================
- Coverage 97.91% 97.84% -0.08%
==========================================
Files 16 16
Lines 1296 1298 +2
==========================================
+ Hits 1269 1270 +1
- Misses 27 28 +1
Continue to review full report at Codecov.
|
|
To start added internal using Tensors
function M11f(A)
l = eigvecs(A)
return symmetric(l[:,1] ⊗ l[:,1])
end
A0 = SymmetricTensor{2,3}((1.2, 0., 0., 0.9, 0., 0.75))
B0 = rand(SymmetricTensor{2,3})
Δ = rand(SymmetricTensor{2,3})*1.e-6
println("A0: ", M11f(A0+Δ) ≈ M11f(A0) + gradient(M11f,A0)⊡Δ)
println("B0: ", M11f(B0+Δ) ≈ M11f(B0) + gradient(M11f,B0)⊡Δ)produces A0: false
B0: trueSeems like the wrong result is caused by a special case given by the A0 tensor in #174. Edit: The function could be discontinuous and AD would then not be properly defined. |
|
Based on Kristoffer's AD talk today, I think function get_cos_sin(u::T,v::T) where {T}
max_abs = max(abs(u), abs(v))
if max_abs > 0
u,v = (u,v) ./ max_abs
len = sqrt(u^2 + v^2)
cs, sn = (u,v) ./ len
if cs > 0
cs = -cs
sn = -sn
end
T(cs), T(sn)
else
T(-1), T(0)
end
endThe problem is that function get_cos_sin(u, v)
α = atan(v, u) + π
return cos(α), sin(α)
endI don't have another solution on top of my head right now for this, so ideas are welcome! |
Tested this with ForwardDiff's NaN-safe mode, but that did not work. Note to possible future implementation: JuliaDiff/ForwardDiff.jl#111 (comment) |
|
Solved by #182 and ForwardDiff.jl-PR575 |
Initial work on solving problem with ad for eigenvalues #174